package com.wude.guild.app;

import android.app.Application;
import android.app.DownloadManager;
import android.content.Context;
import android.os.Build;
import android.support.multidex.MultiDex;
import android.util.Log;

import com.blankj.utilcode.util.ServiceUtils;
import com.blankj.utilcode.util.Utils;
import com.umeng.analytics.MobclickAgent;
import com.wude.guild.BuildConfig;
import com.wude.guild.servercore.Cube;
import com.wude.guild.servercore.util.CubeDebug;
import com.wude.guild.servercore.util.NetworkStatusManager;
import com.wude.guild.servercore.util.PlatFormEnv;
import com.wude.http.HttpCom;
import com.wude.tools.CrashHandler;
import com.wude.tools.Util;

import org.xutils.x;

import in.srain.cube.util.CLog;

/**
 * Created by Administrator on 2017/11/22 0022.
 */

public class GuildApplication extends Application {
    public static GuildApplication application;

    private boolean isPay = true;

    public boolean isPay() {
        return isPay;
    }

    public void setPay(boolean pay) {
        isPay = pay;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();

        application = this;
        x.Ext.init(this);
        // 注册全局异常处理
        CrashHandler.getInstance().init(this);
//        JPushInterface.setDebugMode(true);
//        JPushInterface.init(this);
        Utils.init(this);
        if (!ServiceUtils.isServiceRunning(this, HttpCom.getDownServer())) {
            ServiceUtils.startService(this, DownloadManager.class);
        }

//        if (!ServiceUtils.isServiceRunning(this, HttpCom.TimeServer)) {
//            ServiceUtils.startService(this, TimeService.class);
//        }

        boolean isProd = !BuildConfig.DEBUG;
        PlatFormEnv.setIsProd(!isProd);
        // init log level
        if (PlatFormEnv.isProd()) {
            CLog.setLogLevel(CLog.LEVEL_ERROR);
        } else {
            // development
            CLog.setLogLevel(CLog.LEVEL_VERBOSE);
        }

        CubeDebug.DEBUG_LIFE_CYCLE = isProd;
        CubeDebug.DEBUG_CACHE = isProd;
        CubeDebug.DEBUG_IMAGE = isProd;
        CubeDebug.DEBUG_REQUEST = isProd;
//        PtrFrameLayout.DEBUG = isProd;

        Cube.onCreate(this);
        NetworkStatusManager.init(this);

        //友盟设置场景   E_UM_NORMAL 普通统计场景类型   E_UM_ANALYTICS_OEM  统计盒子场景类型
        MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);
        MobclickAgent.openActivityDurationTrack(false);
        MobclickAgent.enableEncrypt(true);//6.0.0版本及以后

//        if (!(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)) {
//            String deviceInfo = Util.getDeviceInfo(this);
//            Log.d("-----------------", deviceInfo + "");
//        }
    }

    public static Context getApplication() {
        return application;
    }
}
